From de082e05f3a9fb327af4db744134b0ac18fd5ee5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Thu, 27 Mar 2025 11:45:13 +0100 Subject: [PATCH] gui/macOS: Avoid need to retain/release things in file provider edit locally Signed-off-by: Claudio Cambra --- .../macOS/fileprovidereditlocallyjob_mac.mm | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/src/gui/macOS/fileprovidereditlocallyjob_mac.mm b/src/gui/macOS/fileprovidereditlocallyjob_mac.mm index 28ff7fd5b..ec5ffcc75 100644 --- a/src/gui/macOS/fileprovidereditlocallyjob_mac.mm +++ b/src/gui/macOS/fileprovidereditlocallyjob_mac.mm @@ -44,8 +44,7 @@ void FileProviderEditLocallyJob::openFileProviderFile(const QString &ocId) NSFileProviderDomain *const domain = (NSFileProviderDomain *)voidDomain; if (domain == nil) { - qCWarning(lcFileProviderEditLocallyMacJob) << "Could not get domain for account:" - << userId; + qCWarning(lcFileProviderEditLocallyMacJob) << "Could not get domain for account:" << userId; emit notAvailable(); } @@ -56,40 +55,33 @@ void FileProviderEditLocallyJob::openFileProviderFile(const QString &ocId) emit notAvailable(); } - dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); - __block NSError *receivedError; - __block NSURL *itemLocalUrl; [manager getUserVisibleURLForItemIdentifier:nsOcId completionHandler:^(NSURL *const url, NSError *const error) { - [url retain]; - [error retain]; - itemLocalUrl = url; - receivedError = error; - dispatch_semaphore_signal(semaphore); - }]; - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); - - Systray::instance()->destroyEditFileLocallyLoadingDialog(); - if (receivedError != nil) { - const auto errorMessage = QString::fromNSString(receivedError.localizedDescription); - qCWarning(lcFileProviderEditLocallyMacJob) << "Error getting user visible URL for item" - << ocId << ":" << errorMessage; - emit notAvailable(); - } else if (itemLocalUrl != nil) { - const auto itemLocalPath = QString::fromNSString(itemLocalUrl.path); - qCDebug(lcFileProviderEditLocallyMacJob) << "Got user visible URL for item" - << ocId << ":" << itemLocalPath; - [NSWorkspace.sharedWorkspace openURL:itemLocalUrl]; - emit finished(); - } else { - qCWarning(lcFileProviderEditLocallyMacJob) << "Got nil user visible URL for item" - << ocId; - emit notAvailable(); - } + dispatch_async(dispatch_get_main_queue(), ^{ + Systray::instance()->destroyEditFileLocallyLoadingDialog(); + }); - [itemLocalUrl release]; - [receivedError release]; + if (error != nil) { + const auto errorMessage = QString::fromNSString(error.localizedDescription); + qCWarning(lcFileProviderEditLocallyMacJob) << "Error getting user visible URL for item:" << errorMessage; + dispatch_async(dispatch_get_main_queue(), ^{ + emit notAvailable(); + }); + } else if (url != nil) { + const auto itemLocalPath = QString::fromNSString(url.path); + qCDebug(lcFileProviderEditLocallyMacJob) << "Got user visible URL for item:" << itemLocalPath; + [NSWorkspace.sharedWorkspace openURL:url]; + dispatch_async(dispatch_get_main_queue(), ^{ + emit finished(); + }); + } else { + qCWarning(lcFileProviderEditLocallyMacJob) << "Got nil user visible URL for item" << ocId; + dispatch_async(dispatch_get_main_queue(), ^{ + emit notAvailable(); + }); + } + }]; } } // namespace OCC::Mac -- 2.30.2